﻿#pragma once

#include <memory>
#include <vector>
#include <map>
#include "Routine/Common/RoutineConfig.h"
// Config_DruidDlg 对话框

enum IDC_SLIDER_ID_RANGE {
	IDC_SLIDER_MIN = 2000,
	IDC_SLIDER_MAX = 2499,
	IDC_LABEL_MIN = 2500,
	IDC_LABEL_MAX = 2999,
	IDC_EDIT_MIN = 3000,
	IDC_EDIT_MAX = 3399,
};

class Config_DruidDlg : public CDialogEx
{
	DECLARE_DYNAMIC(Config_DruidDlg)

public:
	Config_DruidDlg(SpecializationID spec_id_init, CString title_init, CWnd* pParent = nullptr);   // 标准构造函数
	virtual ~Config_DruidDlg();

	// 对话框数据
#ifdef AFX_DESIGN_TIME
	enum { IDD = IDD_DIALOG_CONFIG_DRUID };
#endif

protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV 支持

	DECLARE_MESSAGE_MAP()
public:
	virtual BOOL OnInitDialog();
private:
	void InitCtrl();

	struct RowCtrls {
		RowCtrls(Property &prop) :ref_prop(prop) {}
		std::vector<std::shared_ptr<CWnd>> vec_ctrl;
		Property &ref_prop;

	};
	std::vector<RowCtrls> rows_ctrls;

	std::shared_ptr<CStatic> CreateTitle(Property &prop, int index, CWnd* copy_ctrl);
	std::shared_ptr<CSliderCtrl> CreateSlide(Property& prop, int index);
	std::shared_ptr<CEdit> CreateEditor(Property& prop, int index);

	void SetEditorContent(Property &prop, CEdit& editor);
	Property &GetSliderProperty(UINT32 slider_id);
	RowCtrls &GetRowCtrlsBySliderID(UINT32 slider_id);
	struct IDRange {
		UINT32 min_id;
		UINT32 max_id;
		UINT32 next_id;
		UINT32 GetAvaildID() {
			return next_id++;
		}
	};

	IDRange slider_id_range = { IDC_SLIDER_MIN, IDC_SLIDER_MAX, IDC_SLIDER_MIN };
	IDRange label_id_range = { IDC_LABEL_MIN, IDC_LABEL_MAX, IDC_LABEL_MIN };
	IDRange editor_id_range = { IDC_EDIT_MIN, IDC_EDIT_MAX, IDC_EDIT_MIN };

	std::map<UINT32, int>  slider_ref_id;

	SpecializationID spec_id = Spec_None;
	CString title;
public:
	afx_msg void OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar);

};
